<template>
  <div class="assetManage">
    <Module-title label="资产管理模块">
      <G-select
        slot="right"
        v-model="queryParams.department_id"
        :options="deptList"
        @change="getList"
      />
    </Module-title>
    <div class="assetManage-row">
      <div
        v-for="(item, k) in typeList"
        :key="k"
        class="assetManage-item"
        :style="{
          backgroundImage: `url(${
            queryParams.type == item.value ? item.activeIcon : item.icon
          })`,
          backgroundSize: '100% 100%',
          backgroundRepeat: 'no-repeat',
          color: queryParams.type == item.value ? '#fff' : '#808080',
        }"
        @click="changeType(item.value)"
      >
        {{ item.label }}
      </div>
      <div class="assetManage-search">
        <el-input
          v-model="queryParams.name"
          prefix-icon="el-icon-search"
          :placeholder="`请输入${queryParams.type == '1' ? '设备' : '通用'}名称`"
          clearable
          @keyup.enter.native="getList"
          @blur="getList"
          @clear="getList"
        />
      </div>
    </div>
    <G-table id="asset" height="130px" :speed="50" :columns="columns" :data="dataList" />
  </div>
</template>
<script>
import { getDeviceCost } from "@/utils/srceen";
import device from "@/assets/device.png";
import deviceActive from "@/assets/device-active.png";
import general from "@/assets/general.png";
import generalActvie from "@/assets/general-active.png";
export default {
  name: "asset-manage-srceen",
  props: {
    // 科室列表
    deptList: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {
      queryParams: {
        department_id: "",
        name: "",
        type: "1",
      },
      typeList: [
        { label: "设备名称资产表", value: "1", icon: device, activeIcon: deviceActive },
        { label: "通用名称资产表", value: "2", icon: general, activeIcon: generalActvie },
      ],
      columns: [
        { label: "设备名称", prop: "name" },
        { label: "数量", prop: "count" },
        { label: "总价（元）", prop: "price" },
      ],
      dataList: [],
    };
  },
  watch: {
    deptList: {
      handler(val) {
        if (val.length) {
          this.queryParams.department_id = val[0].id;
          this.getList();
        }
      },
      immediate: true,
    },
  },
  methods: {
    // 切换类型
    changeType(type) {
      this.columns[0].label = type == "1" ? "设备名称" : "通用名称";
      this.queryParams.type = type;
      this.getList();
    },
    // 获取表格数据
    getList() {
      getDeviceCost(this.queryParams).then((res) => {
        if (res && res.code == 1) {
          this.dataList = res.data || [];
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.assetManage {
  width: 100%;
  height: 248px;
  background-color: rgba(0, 37, 111, 0.4);
  &-row {
    display: flex;
    align-items: center;
    margin: 13px 10px 16px;
    .assetManage-item {
      width: 100px;
      height: 41px;
      font-family: PingFang SC;
      font-weight: bold;
      font-size: 11px;
      line-height: 13px;
      padding-left: 45px;
      padding-right: 10px;
      text-align: center;
      box-sizing: border-box;
      display: flex;
      align-items: center;
      &:hover {
        cursor: pointer;
      }
    }
    .assetManage-search {
      flex: 1;
      margin-left: 10px;
      height: 41px;
    }
    ::v-deep .el-input__inner {
      background: linear-gradient(
        270deg,
        rgba(1, 135, 191, 0.3) 0%,
        rgba(1, 135, 191, 0) 100%
      ) !important;
      border: none !important;
      color: #fff !important;
      &::placeholder {
        color: #fff;
      }
    }
  }
}
</style>
